home *** CD-ROM | disk | FTP | other *** search
- unit SpyConfigure;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, SpyEngine, ExtCtrls;
-
- type
- TfrmSpyConfigure = class(TForm)
- gbOptions1: TGroupBox;
- cbWndMsgs: TCheckBox;
- cbCNMsgs: TCheckBox;
- cbCMMsgs: TCheckBox;
- pnlRight: TPanel;
- btnOK: TButton;
- btnCancel: TButton;
- lblControl: TLabel;
- cbControl: TComboBox;
- rgMonitorFrom: TRadioGroup;
- gbFilters: TGroupBox;
- cbConsecutiveMessages: TCheckBox;
- cbHeavyHitters: TCheckBox;
- procedure FormShow(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure btnOKClick(Sender: TObject);
- private
- MessageSpy: TMessageSpy;
- ControlList: TStringList;
- procedure LoadComboBox;
- procedure SetControlsFromOptions;
- procedure SetOptionsFromControls;
- public
- end;
-
- var
- frmSpyConfigure: TfrmSpyConfigure;
-
- implementation
-
- {$R *.DFM}
-
- procedure TfrmSpyConfigure.btnOKClick(Sender: TObject);
- begin
- SetOptionsFromControls;
- Close;
- end;
-
- procedure TfrmSpyConfigure.FormDestroy(Sender: TObject);
- begin
- ControlList.Free;
- end;
-
- procedure TfrmSpyConfigure.FormShow(Sender: TObject);
- begin
- ControlList := TStringList.Create;
- MessageSpy := TMessageSpy(Owner);
- SetControlsFromOptions;
- end;
-
- procedure TfrmSpyConfigure.LoadComboBox;
- var
- I: Integer;
- F: TCustomForm;
- C: TComponent;
- begin
- F := TCustomForm(MessageSpy.Owner);
- ControlList.AddObject('<None>', nil);
- ControlList.AddObject(F.Name, F);
- for I := 0 to F.ComponentCount - 1 do
- begin
- C := F.Components[I];
- if C is TMessageSpy then
- // skip it
- else if C is TControl then
- begin
- if C.Name <> '' then
- ControlList.AddObject(C.Name, C)
- else
- ControlList.AddObject('anonymous ' + C.ClassName, C);
- end;
- end;
- cbControl.Items.Assign(ControlList);
- end;
-
- procedure TfrmSpyConfigure.SetControlsFromOptions;
- var
- I: Integer;
- begin
- cbWndMsgs.Checked := mtWindowsMessage in MessageSpy.MessageTypes;
- cbCNMsgs.Checked := mtCN_Message in MessageSpy.MessageTypes;
- cbCMMsgs.Checked := mtCM_Message in MessageSpy.MessageTypes;
- cbConsecutiveMessages.Checked := MessageSpy.FilterConsecutiveMessages;
- cbHeavyHitters.Checked := MessageSpy.FilterHeavyHitters;
- case MessageSpy.HookType of
- htWndProc: rgMonitorFrom.ItemIndex := 0;
- htDispatch: rgMonitorFrom.ItemIndex := 1;
- htBoth: rgMonitorFrom.ItemIndex := 2;
- end;
- LoadComboBox;
- cbControl.ItemIndex := 0;
- I := ControlList.IndexOfObject(MessageSpy.Hookee);
- if I <> -1 then
- cbControl.ItemIndex := I;
- end;
-
- procedure TfrmSpyConfigure.SetOptionsFromControls;
- var
- MT: TMessageTypes;
- begin
- MT := [];
- if cbWndMsgs.Checked then
- Include(MT, mtWindowsMessage);
- if cbCNMsgs.Checked then
- Include(MT, mtCN_Message);
- if cbCMMsgs.Checked Then
- Include(MT, mtCM_Message);
- MessageSpy.MessageTypes := MT;
- MessageSpy.FilterConsecutiveMessages := cbConsecutiveMessages.Checked;
- MessageSpy.FilterHeavyHitters := cbHeavyHitters.Checked;
- case rgMonitorFrom.ItemIndex of
- 0: MessageSpy.HookType := htWndProc;
- 1: MessageSpy.HookType := htDispatch;
- 2: MessageSpy.HookType := htBoth;
- end;
- MessageSpy.Hookee := TControl(ControlList.Objects[cbControl.ItemIndex]);
- end;
-
- end.
-